﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Plugins;

namespace MethodWorx.CMS.Workflow.IfEquals
{
    public class IfEqualsWorkflowComponent : WorkflowComponent<IfEqualsConfigurationController>
    {
        public IfEqualsWorkflowComponent(Plugin plugin)
            : base(plugin)
        {
        }

        public static Guid ComponentId = Guid.Parse("{73F90C86-BFB9-4A7A-AC8C-880B664FD40C}");

        public override Guid Id
        {
            get { return ComponentId;  }
        }

        public override string Category
        {
            get { return "Flow";  }
        }

        public override string Name
        {
            get { return "If Equals";  }
        }

        public override string Description
        {
            get { return "Provides program flow based on equality of data";  }
        }

        public override string View
        {
            get { return "IfEqualsConfigurationView.ascx";  }
        }

        public override StepExecutionResult Execute(IWorkflowExecutionContext context, IWorkflowConfiguration configuration)
        {
            var c = (IfEqualsConfiguration) configuration;
            var v1 = context.GetWorkflowValue(c.VariableName1);
            var v2 = context.GetWorkflowValue(c.VariableName2);
            if (v1 == v2)
                return StepExecutionResult.Ok(0);
            else
                return StepExecutionResult.Ok(1);
                
        }
    }
}
